| Conditions | 7 |
| Total Lines | 52 |
| Code Lines | 42 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | import type { PathLike } from "fs" |
||
| 11 | |||
| 12 | async function main() { |
||
| 13 | const templatesDir = `${__dirname}/template/` |
||
| 14 | , files = sync(`**/*`, { |
||
| 15 | "gitignore": true, |
||
| 16 | "cwd": templatesDir |
||
| 17 | }) |
||
| 18 | , vars = await readMd(`${__dirname}/input.md`) |
||
| 19 | |||
| 20 | await appenderSync(`${__dirname}/output/input.env`)(...vars[""]) |
||
| 21 | |||
| 22 | for (const file of files) { |
||
| 23 | const outputFile = `${__dirname}/output/${file}` |
||
| 24 | , reader = createLineReader(`${templatesDir}${file}`) |
||
| 25 | , append = appenderSync(outputFile) |
||
| 26 | |||
| 27 | for await (const line of reader) { |
||
| 28 | const templ = templateLine<"type"|"prefix">(line) |
||
| 29 | |||
| 30 | if (!templ) { |
||
| 31 | await append(line, "\n") |
||
| 32 | continue |
||
| 33 | } |
||
| 34 | |||
| 35 | const { |
||
| 36 | indentation, |
||
| 37 | type = "", |
||
| 38 | prefix = "" |
||
| 39 | } = templ |
||
| 40 | |||
| 41 | if (!(type in vars)) |
||
| 42 | throw Error(`Unknown type: "${type}"`) |
||
| 43 | |||
| 44 | const vars4type = vars[type] |
||
| 45 | |||
| 46 | await append( |
||
| 47 | ...Object.keys(vars4type) |
||
| 48 | .map(e => { |
||
| 49 | const status = vars4type[e] |
||
| 50 | |||
| 51 | return arr2line( |
||
| 52 | indentation, |
||
| 53 | status && status !== "-" ? "" : "#", |
||
| 54 | prefix, |
||
| 55 | e |
||
| 56 | ) |
||
| 57 | }) |
||
| 58 | ) |
||
| 59 | } |
||
| 60 | } |
||
| 61 | |||
| 62 | return files |
||
| 63 | } |
||
| 135 |